//
// Created by shao.liming on 10/29/2017.
//

#include "E242.h"
#include <iostream>
#include <map>

bool E242::isDeformation(std::string str1, std::string str2) {
    std::map<char, int> strMap;
    if(str1.empty() || str2.empty() || str1.length() != str2.length()){
        return false;
    }

    // Use range-based-for
    for (char i : str1) {
        strMap[i]++;
    }

    for (char j : str2) {
        if(--strMap[j] < 0){
            return false;
        }
    }

//    for (int j = 0; j < str2.length(); ++j) {
//        if(--strMap[str2[j]] < 0){
//            return false;
//        }
//    }

    return true;
}

void E242::test() {
    std::string s1 = "11324liming";
    std::string s2 = "34121liimng";
    std::cout << (isDeformation(s1, s2)?"is Deformation":"not Deformation") << std::endl;
}
